<template>
  <div class="login">
    <el-form :model="loginForm" label-position="left" label-width="60px" class="login-form">
      <h1>登录</h1>
      <el-form-item label="用户名" prop="username">
        <el-input v-model="loginForm.username" placeholder="请输入用户名"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input type="password" v-model="loginForm.password" placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script setup>

import { reactive } from 'vue'
import { reqMenuList } from '@/api/permission.js'
import { useUserInfoStore } from '@/store/userInfo.js'
import { useRouter } from 'vue-router'

const router = useRouter()
const loginForm = reactive({
  username: '',
  password: ''
})
const userInfoStore = useUserInfoStore()
const onSubmit = async () => {
  const res = await reqMenuList(loginForm)
  console.log(res)
  userInfoStore.updateMenuList(res.data.menuList)
  userInfoStore.token = res.data.token
  userInfoStore.addMenu(router)
  await router.push('/')
}

</script>

<style scoped lang="less">
.login{
  width: 100%;
  height: 100%;
  background: url("../assets/images/login.jpg") center no-repeat;
  background-size: cover;
  overflow: hidden;
}
.login-form{
  width: 350px;
  background-color: #fff;
  border: 1px solid #eaeaea;
  border-radius: 15px;
  padding: 35px 35px 15px;
  box-shadow: 0 0 25px #cacaca;
  margin:  250px auto;
  h1{
    text-align: center;
    margin-bottom: 20px;
    color: #505450;
    font-size: 22px;
  }
  :deep(.el-form-item__content){
    justify-content: center;
  }
}
</style>
